package com.nodusk.util;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class test {
    public static void main(String[] args) throws ParseException {

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM"); //格式化时间
//获取上个月的第一天
        Calendar cal_1=Calendar.getInstance();//获取当前日期
        cal_1.add(Calendar.MONTH, -1);
        cal_1.set(Calendar.DAY_OF_MONTH,1);//设置为1号
        cal_1.set(Calendar.HOUR_OF_DAY,0);
        cal_1.set(Calendar.MINUTE,0);
        cal_1.set(Calendar.SECOND,0);
        String firstDay = format.format(cal_1.getTime());
        System.out.println(format.parse(firstDay).getTime());
        System.out.println(firstDay);
//例如今天 2021/8/11 sout后会输出：2021/7/1 00:00:00


//        BigDecimal e=new BigDecimal(1);
//        BigDecimal r=new BigDecimal(1);
//
//        System.out.println( compareAmount("<",e,r));

    }

    public static boolean compareAmount(String comparator, BigDecimal before,BigDecimal later){
        boolean flag=false;
        switch (comparator){
            case "<" :
                flag= before.compareTo(later) < 0;
                break;
            case "<=" :

                flag=  before.compareTo(later)<= 0;
                break;
            case "==" :
                flag=  before.compareTo(later)== 0;
                break;
            case ">=" :
                flag=  before.compareTo(later)>= 0;
                break;
            case ">" :
                flag=  before.compareTo(later)> 0;
                break;

        }
        return flag;
    }
}
